/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.ArrayList;
import javax.ejb.Stateless;
import javax.inject.Named;

/**
 *
 * @author Emergenza
 */
@Named ("daySpecificationBean")
@Stateless
public class DaySpecificationBean {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    private final int NUMBEROFVISUALIZEDRESULT = 5;
    private ArrayList<Event> events;
    private int base;
    

    public DaySpecificationBean() {
        System.out.println("costruttore auto");
        Event e = new Event("EVENTNAME", "EVENTDESCRIPTION", "SUNNY");
        System.out.println("e creato");
        events = new ArrayList<Event>();
        events.add(e);
        e = new Event("EVENTNAME2", "EVENTDESCRIPTION2", "RAINY");
        events.add(e);
        base = 0;
    }

    public String getEventname(int i) {
        System.out.println("name letto" + (i));
        if(events.size()>0 && (events.size()-1) >= (i + base)){
            System.out.println("searched.size()"  + events.size());
            return(events.get(i + base).getName());
        }else{
            return("");
        }
    }
    public String getEventDesc(int i) {
        System.out.println("name letto" + (i));
        if(events.size()>0 && (events.size()-1) >= (i + base)){
            System.out.println("searched.size()"  + events.size());
            return(events.get(i + base).getDescription());
        }else{
            return("");
        }
    }
    public String getEventWea(int i) {
        System.out.println("name letto" + (i));
        if(events.size()>0 && (events.size()-1) >= (i + base)){
            System.out.println("searched.size()"  + events.size());
            return(events.get(i + base).getWeather());
        }else{
            return("");
        }
    }
    
    /**
     * increase the value of the base of NUMBEROFVISUALIZEDRESULT to visualize the following set of result
     */
    public void next() {
        System.out.println(base);
        if(base < events.size()-NUMBEROFVISUALIZEDRESULT){
            base = base + NUMBEROFVISUALIZEDRESULT;
        }
    }
    
    /**
     * decrease the value of the base of NUMBEROFVISUALIZEDRESULT to visualize the previous set of result
     */
    public void prev() {
        System.out.print(base);
        if(base > 0){
            base = base - NUMBEROFVISUALIZEDRESULT;
        }
    } 
}
